/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package easybooking.clients.gui.editor;

import easybooking.data.Type;
import java.rmi.RemoteException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.AbstractTableModel;

/**
 * The table model fpr types
 * @author Tim Schröder
 */
public class TypeTableModel extends AbstractTableModel {

    /**
     * Vector which contains all types
     */
    private Vector<Type> types;
    /**
     * The index of the column where the ID get insert
     */
    private static final int ID_INDEX = 0;
    /**
     * The index of the column where the Name get insert
     */
    private static final int NAME_INDEX = 1;
    /**
     * The index of the column where the row get insert
     */
    private static final int ROWS_INDEX = 2;
    /**
     * The index of the column where the colmn get insert
     */
    private static final int COLUMNS_INDEX = 3;
    /**
     * The index of the column where the number of all seats get insert
     */
    private static final int SEATSTOTAL_INDEX = 4;
    /**
     * Index to get the Object which is selected
     */
    private static final int OBJECT = 5;
    /**
     * Names of columns
     */
    private String[] columnNames = {"ID", "Name", "Rows", "Columns", "Seats Total"};

    public TypeTableModel(Vector<Type> t) {
        types = t;
    }

    /**
     * get the number of rows the table needs
     * @return the number of type objects in the types Vector
     */
    public int getRowCount() {
        return types.size();
    }

    /**
     * get the number of columns
     * @return the number of the column Names
     */
    public int getColumnCount() {
        return columnNames.length;

    }

    @Override
    /**
     * get the name of a column
     * @param col is the number of the column which name is wanted
     * @return the name of a column
     */
    public String getColumnName(int col) {
        return columnNames[col];
    }

    /**
     * prepares the airline data for the table
     * @param rowIndex the row in which the data get insert
     * @param columnIndex the column in which the data get insert
     * @return the prepared object
     */
    public Object getValueAt(int rowIndex, int columnIndex) {
        try {
            Type t = (Type) types.get(rowIndex);
            switch (columnIndex) {
                case ID_INDEX:
                    return t.getTypeId();
                case NAME_INDEX:
                    return t.getName();
                case ROWS_INDEX:
                    return t.getRows();
                case COLUMNS_INDEX:
                    return t.getColumns();
                case SEATSTOTAL_INDEX:
                    return t.getSeatsTotal();
                case OBJECT:
                    return t;
                default:
                    return new Object();
            }
        } catch (RemoteException ex) {
            Logger.getLogger(TypeTableModel.class.getName()).log(Level.SEVERE, null, ex);
            return new Object();
        }
    }
}

